<?php
include $_SERVER['DOCUMENT_ROOT']."/pos/lib/head_lv2.php";
$dir = "up_file/";

function page_avg($totalpage,$cpage){
	if(!$pagenumber) {
		$pagenumber = 10;
	}

	$startpage = intval(($cpage - 1) / $pagenumber) * $pagenumber +1  ;
	$endpage = intVal(((($startpage -1) +  $pagenumber) / $pagenumber) * $pagenumber) ;
	if ($totalpage <= $endpage)
	$endpage = $totalpage;
	if ( $cpage > $pagenumber) {
		$curpage = intval($startpage - 1);
		$url_page = "<a href=javascript:page_move($curpage) class='page_number'>";
		echo ("$url_page");
		echo("◀.. </a>");
	}
	else{
	}
	$curpage = $startpage;

	while ($curpage <= $endpage):
	if ($curpage == $cpage) {
		echo "<b class='page_number' style='color:#FF5005;'>$cpage</b>";
	} else {
		$url_page = "<a href=javascript:page_move($curpage) class='page_number'>";
		echo ("$url_page");
		echo("$curpage</a>");
	}
	$curpage++;

	endwhile ;
	if ( $totalpage > $endpage) {
		$curpage = intval($endpage + 1);
		$url_page = "<a href=javascript:page_move($curpage) class='page_number'>";
		echo ("$url_page");
		echo(".. ▶</a>");
	}
	else{
	}
}

function page_division($scale,$total,$pagediv){
	if ($pagediv	==	''){
		$pagediv	=	1;
	}
	
	$page = array(
		'cline'		=> 0,
		'scale1'	=> 0,
		'totalpage'	=> 0,
		'cpage'		=> 0
	);
	
	$page['cpage'] = intval($pagediv);//현재 페이지
	$page['totalpage'] = intval($total/$scale); //전체 페이지 갯수
	if ($page['totalpage'] * $scale != $total){
	$page['totalpage'] = $page['totalpage'] + 1;
	}
	if ($cpage ==1) {
		$page['cline'] = 0 ;
	} else {
		$page['cline'] = ($page['cpage']*$scale) - $scale ;
	}
	
	$limit = $page['cline'] + $scale;
	
	if ($limit >= $total)
	$limit = $total;
	
	$page['scale1'] = $limit - $page['cline'];	
	return $page;
}

function insert_shopinfo($sg_no,$s_no){
	if($sg_no != '-1'){
		$sear_sg = "and sg_no != '-1'";;
	}
	if($sg_no){
		$sear_sg .= "and sg_no = $sg_no";;
	}

	$sql = "select * from uatp_shopinfo where 1 $sear_sg order by no DESC";
	$result = DBquery($sql);
	for($i=1; $list = mysql_fetch_array($result); $i++){
		if($list['no']==$s_no){
			$category_option .= "<option value=".$list['no']." selected>".$list['name']."</option>";
		}//selet box 고정
		else{
			$category_option .= "<option value=".$list['no'].">".$list['name']."</option>";
		}
	}
	echo "<select style='font-size:11px;' name='s_no[]'>".$category_option."</select>";
}


function insert_shopgroup($sg_no){

	if($sg_no != '-1'){
		$sear_sg = "and no != '-1'";;
	}
	
	$sql = "select * from uatp_shopgroup where 1 $sear_sg order by no DESC";
	$result = DBquery($sql);
	for($i=1; $list = mysql_fetch_array($result); $i++){
		if($list['no']==$sg_no){
			$category_option .= "<option value=".$list['no']." selected>".$list['name']."</option>";
		}//selet box 고정
		else{
			$category_option .= "<option value=".$list['no'].">".$list['name']."</option>";
		}
	}

	echo "<select style='font-size:11px;' name='sg_no[]'>".$category_option."</select>";
}


function shopgroup($sg_no){
	$sql = "select * from uatp_shopgroup order by no DESC";
	$result = DBquery($sql);
	for($i=1; $list = mysql_fetch_array($result); $i++){
		if($list['no']==$sg_no){
			$category_option = $category_option."<option value=".$list['no']." selected>".$list['name']."</option>";
		}//selet box 고정
		else{
			$category_option = $category_option."<option value=".$list['no'].">".$list['name']."</option>";
		}
	}
	echo "<select name='sg_no' onchange='javascript:shopgroup(this.value);' style='font-size:11px'>
	<option value=''>점포그룹</option>".$category_option."
	</select>";
}		


function shopinfo($sg_no,$s_no){
	if ($sg_no){
	$sear_char = " and sg_no = $sg_no";
	$sql = "select * from uatp_shopinfo where 1 $sear_char order by no DESC";
	$result = DBquery($sql);
	for($i=1; $list = mysql_fetch_array($result); $i++){
		if($list['no']==$s_no){
			$category_option = $category_option."<option value=".$list['no']." selected>".$list['name']."</option>";
		}//selet box 고정
		else{
			$category_option = $category_option."<option value=".$list['no'].">".$list['name']."</option>";
		}
	}
	echo "<select name='s_no' onchange='javascript:shopinfo(\"view.php\",".$sg_no.",this.value);' style='font-size:11px'>
	<option value=''>전체</option>".$category_option."
	</select>";
	}
	else{
		echo "<select name='s_no' style='font-size:11px'>
			<option value=''>::점포그룹을 선택해 주세요</option></select>";
	}
}

function insert_middle($b_no,$m_no){
	if($b_no){
		$sear_b = "and b_no = $b_no";
		$sql = "select * from uatp_middlecategory where 1 $sear_b order by no DESC";
		$result = DBquery($sql);
		for($i=1; $list = mysql_fetch_array($result); $i++){
		if($list['no']==$m_no){
		$category_option .= "<option value=".$list['no']." selected>".$list['name']."</option>";
		}//selet box 고정
		else{
		$category_option .= "<option value=".$list['no'].">".$list['name']."</option>";
				}
			}
	}else{
		$category_option = "<option value=''>::중분류::</option>";
	}
	echo "<select style='font-size:11px;' name='m_no[]'>".$category_option."</select>";
}

function insert_big($b_no){
	$sql = "select * from uatp_biggestcategory order by no DESC";
	$result = DBquery($sql);
	$category_option = "<option value='0'>::대분류::</option>";
	for($i=1; $list = mysql_fetch_array($result); $i++){
		if($list['no']==$b_no){
			$category_option = $category_option."<option value=".$list['no']." selected>".$list['name']."</option>";
		}//selet box 고정
		else{
			$category_option = $category_option."<option value=".$list['no'].">".$list['name']."</option>";
		}
	}
	echo "<select style='font-size:11px' name='b_no[]'>".$category_option."</select>";
}


function c_big($b_no){
	$sql = "select * from uatp_biggestcategory order by no DESC";
	$result = DBquery($sql);
	for($i=1; $list = mysql_fetch_array($result); $i++){
		if($list['no']==$b_no){
			$category_option = $category_option."<option value=".$list['no']." selected>".$list['name']."</option>";
		}//selet box 고정
		else{
			$category_option = $category_option."<option value=".$list['no'].">".$list['name']."</option>";
		}
	}
	echo "<select name='b_no[]' onchange='javascript:b_no(this.value);' style='font-size:11px'>
	<option value=''>전체</option>".$category_option."
	</select>";
}


function c_middle($b_no,$m_no){
	if ($b_no){
	$sear_cate = " and b_no = $b_no";
	$sql = "select * from uatp_middlecategory where 1 $sear_cate order by no DESC";
	$result = DBquery($sql);
	for($i=1; $list = mysql_fetch_array($result); $i++){
		if($list['no']==$m_no){
			$category_option = $category_option."<option value=$list[no] selected>$list[name]</option>";
		}//selet box 고정
		else{
			$category_option = $category_option."<option value=$list[no]>$list[name]</option>";
		}
	}
	echo "<select name=sca onchange='javascript:select_m_category(\"view.php\",".$b_no.",this.value);' style='font-size:11px'>
	<option value=''>전체</option>".$category_option."
	</select>";
	}
	else{
		echo "<select name=sca style='font-size:11px'>
			<option value=''>::대분류를 먼저 선택해 주세요</option></select>";
	}
}